From: Sebastian Keller Date: Tue, 15 Jul 2025 08:08:45 +0000 (+0200) Subject: util: Don't consider consecutive dots as URLs X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~116^2^2~54 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=5af26a21810cdc26965137d5c30864ad782db5b6;p=gnome-shell.git util: Don't consider consecutive dots as URLs This now requires at least one character separating each dot for it to be considered a URL. It also does not allow URLs starting with a dot anymore. Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/8517 Part-of: --- diff --git a/js/misc/util.js b/js/misc/util.js index 0a6bf1932..0101ecffb 100644 --- a/js/misc/util.js +++ b/js/misc/util.js @@ -20,7 +20,7 @@ const _urlRegexp = new RegExp( '|' + 'www\\d{0,3}[.]' + // www. '|' + - '[a-z0-9.\\-]+[.][a-z]{2,4}/' + // foo.xx/ + '([a-z0-9\\-]+[.])+[a-z]{2,4}/' + // foo.xx/ ')' + '(?:' + // one or more: '[^\\s()<>]+' + // run of non-space non-() diff --git a/tests/unit/url.js b/tests/unit/url.js index 28ef0fa28..0542565d8 100644 --- a/tests/unit/url.js +++ b/tests/unit/url.js @@ -53,6 +53,14 @@ describe('findUrls()', () => { input: 'This is a www.gnome.org/scheme-less test.', output: [{url: 'www.gnome.org/scheme-less', pos: 10}], }, + { + input: 'This is a gnome.org/scheme-less test without www.', + output: [{url: 'gnome.org/scheme-less', pos: 10}], + }, + { + input: 'This is a status.gnome.org/scheme-less test.', + output: [{url: 'status.gnome.org/scheme-less', pos: 10}], + }, { input: 'This is a http://www.gnome.org:99/port test.', output: [{url: 'http://www.gnome.org:99/port', pos: 10}], @@ -104,6 +112,18 @@ describe('findUrls()', () => { input: 'This is surely@not.a/url test.', output: [], }, + { + input: 'This is not..aa/url test.', + output: [], + }, + { + input: 'This is ..not/a-url test.', + output: [], + }, + { + input: 'This is .absolutely.not/a-url test.', + output: [], + }, ]; for (const param of urlParameters) {